<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../common/base_body_header.jsp" %>
<%@include file="../common/navbar.jsp" %>
<%@include file="../common/page_content_pre.jsp" %>

<link rel="stylesheet" href="${GLOBAL.staticJsPath}/assets/qiniu/fileupload.css"/>

<div class="page-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="widget-box">
                <div class="widget-header">
                    <h4>${not empty customer.customerId?'修改':'添加'}客户</h4>
                </div>

                <div class="widget-body">
                    <div class="widget-main no-padding">
                        <form:form class="form-horizontal" modelAttribute="customer" enctype="multipart/form-data"
                                   action="${GLOBAL.basePath}/customer/save" method="post" id="customerForm">
                            <form:input path="customerId" type = "hidden"/>
                            <fieldset style="display: none;">
                                <div class="form-group">
                                    <span class="col-sm-3 control-label">客户编号：</span>
                                    <label class="control-label">${customer.customerId}</label>
                                </div>
                            </fieldset>

                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">客户姓名：</label>

                                    <div class="col-sm-5">
                                        <form:input path="customerName" htmlEscape="false"
                                                    class="input-xlarge required" placeholder="请输入客户姓名"/>
                                        <span class="help-inline"><font color="red">*</font> </span>
                                    </div>
                                </div>
                            </fieldset>

                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">联系方式：</label>

                                    <div class="col-sm-5">
                                        <form:input path="customerPhone" htmlEscape="false"
                                                    class="input-xlarge required" placeholder="请输入联系方式"/>
                                        <span class="help-inline"><font color="red">*</font> </span>
                                    </div>
                                </div>
                            </fieldset>

                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">客户状态：</label>
                                    <div class="col-sm-4">
                                        <form:select class="input-xlarge" path="staus">
                                            <c:forEach items="${fns:getDictList('customer_status')}" var="item">
                                                <option value="${item.name}" <c:if test="${item.name == customer.staus}">selected</c:if>>${item.value}</option>
                                            </c:forEach>
                                        </form:select>
                                    </div>
                                </div>
                            </fieldset>

                            <div class="form-actions center">
                                <button type="button" class="btn btn-sm btn-grey" id="go_back_btn">
                                    返回
                                    <i class="icon-reply icon-on-right bigger-110"></i>
                                </button>
                                <shiro:hasPermission name='customer:edit'>
                                    <button type="submit" class="btn btn-sm btn-success" id="save_btn">
                                        保存
                                        <i class="icon-save icon-on-right bigger-110"></i>
                                    </button>
                                </shiro:hasPermission>
                                <%--<c:if test="${not empty customer.customerId}">--%>
                                    <%--<shiro:hasPermission name='follow:view'>--%>
                                        <%--<button type="button" class="btn btn-sm btn-info" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">--%>
                                            <%--跟进--%>
                                            <%--<i class="icon-save icon-on-right bigger-110"></i>--%>
                                        <%--</button>--%>
                                    <%--</shiro:hasPermission>--%>
                                <%--</c:if>--%>
                            </div>
                        </form:form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog"aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="exampleModalLabel">跟进</h4>
                </div>
                <div class="modal-body">
                    <div class="input-group">
                        <span class="input-group-addon">跟进时间:</span>
                        <input name="followDate" id="followDateId" readonly="true" style="width: 30%"
                               class="form-control required" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>
                    </div>
                    &nbsp;
                    <div class="input-group">
                        <span class="input-group-addon">跟进信息:</span>
                        <textarea type="text" class="form-control col-sm-9" cols="3" id="followInfo" style="height: 150px;"></textarea>
                    </div>
                    <span style="float: right; color: red;" id="infoId"></span>
                    <div>&nbsp;</div>
                </div>
                <div class="modal-footer" style="">
                    <button type="button" class="btn btn-sm btn-primary subUpdate" data-dismiss=""
                            onclick="addFollow(this)">确认</button>
                    <button type="button" class="btn btn-sm btn-info" data-dismiss="modal" onclick="closeValue()">取消</button>
                </div>
            </div>
        </div>
    </div>
    <input id = "customer_id" type="hidden" value="${customer.customerId}">
</div>

<%@include file="../common/page_content_suf.jsp" %>
<%@include file="../common/script.jsp" %>

<script type="text/javascript" src="${GLOBAL.staticJsPath}/assets/my97/WdatePicker.js"></script>

<script type="text/javascript">
    //展览下拉选项
    ART.mLoadSelectOption("${GLOBAL.basePath}/order/exhibitionList", {}, $("#s_pItemKey"), "id", "title", true);

    $(document).ready(function () {
        $("#go_back_btn").on("click", function () {
            goBack();
        });

        $("#customerForm").validate({
            rules: {
            },
            messages: {
                mobile: {required: "用户登录名不能为空", remote: jQuery.format("用户登录名已存在")},
                confirmNewPassword: {equalTo: "输入与上面相同的密码"}
            }
        });

        $("#save_btn").on("click", function () {
            saveBtn();
        });
    });

    function goBack() {
        document.location.href = "${GLOBAL.basePath}/customer/list";
    }

    function addFollow(obj){
        var followInfo = $("#followInfo").val();
        var followDate = $("#followDateId").val();
        $("#infoId").html("");
        if(followDate != null && followDate != ""){
            if(followInfo != null && followInfo != ""){
                $.ajax({
                    url : "${GLOBAL.basePath}/follow/save",
                    type : "post",
                    async : false,
                    data : {
                        followInfo : $("#followInfo").val(),
                        relationId : $("#customer_id").val(),
                              type : "2",
                        followDate : $("#followDateId").val()
                    },
                    success : function(data){
                        if(data){
                            obj.setAttribute('data-dismiss', 'modal');
                            document.location.href = "${GLOBAL.basePath}/customer/edit?customerId=" + $("#customer_id").val();
                        }
                    }

                })
            }else {
                $("#infoId").html("跟进信息不能为空!")
            }
        }else{
            $("#infoId").html("跟进时间不能为空!")
        }
    }

    function closeValue(){
        $("#followInfo").val("");
        $("#followDateId").val("");
        $("#infoId").html("")
    }
</script>
